package com.example.xinli.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.xinli.dao.RecordMapper;
import com.example.xinli.dao.ZidongsiweiMapper;
import com.example.xinli.domain.entity.Record;
import com.example.xinli.domain.entity.Zidongsiwei;
import com.example.xinli.domain.vo.ResponseBean;
import com.example.xinli.domain.vo.ResponseBeanEnum;
import com.example.xinli.domain.vo.ZidongsiweiSubmitVo;
import com.example.xinli.service.IRecordService;
import com.example.xinli.service.IZidongsiweiService;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class ZidongsiweiServiceImpl extends ServiceImpl<ZidongsiweiMapper, Zidongsiwei> implements IZidongsiweiService {

    @Autowired
    ZidongsiweiMapper zidongsiweiMapper;

    @Override
    public ResponseBean getAllUserZidongsiwei(String userId) {
        QueryWrapper<Zidongsiwei> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        List<Zidongsiwei> zidongsiweiList = zidongsiweiMapper.selectList(queryWrapper);
        return ResponseBean.success(zidongsiweiList);
    }

    @Override
    public ResponseBean submitZidongsiwei(ZidongsiweiSubmitVo zidongsiweiSubmitVo) {
        Zidongsiwei zidongsiwei = new Zidongsiwei();
        zidongsiwei.setUserId(zidongsiweiSubmitVo.getUserId());
        zidongsiwei.setSiweiName(zidongsiweiSubmitVo.getSiweiName());
        zidongsiwei.setDate(zidongsiweiSubmitVo.getDate());
        zidongsiwei.setMonsterUrl(zidongsiweiSubmitVo.getMonsterUrl());
        zidongsiwei.setQingjing(zidongsiweiSubmitVo.getQingjing());
        zidongsiwei.setGanshou(zidongsiweiSubmitVo.getGanshou());
        zidongsiwei.setZidongsiwei(zidongsiweiSubmitVo.getZidongsiwei());
        zidongsiwei.setHouxuyingxiang(zidongsiweiSubmitVo.getHouxuyingxiang());
        zidongsiwei.setRuheshibie(zidongsiweiSubmitVo.getRuheshibie());
        zidongsiwei.setRecordId(-1);

        int res = zidongsiweiMapper.insert(zidongsiwei);
        if (res > 0) {
            return ResponseBean.success();
        }
        return ResponseBean.error(ResponseBeanEnum.ERROR);
    }
}

